import axios from 'axios'
import Qs from 'qs'
// import { Message } from 'element-ui'

const baseURL = process.env.baseURL
const instance = axios.create({
  baseURL: baseURL,
  timeout: 100000,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  transformRequest: [function (data) {
    data = Qs.stringify(data)
    console.log(data)
    return data
  }]
})

instance.interceptors.request.use(function (config) {
  // Do something before request is sent
  config.data = config.data || {}
  config.data.local = 'zh_TW'
  console.log(config)
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// Add a response interceptor
instance.interceptors.response.use(function (response) {
  // Do something with response data
  return response
}, function (error) {
  // Do something with response error
  // Message.error(error.message)
  return Promise.reject(error)
})

export default instance
